//
//  VL0View.m
//  DoorBell
//
//  Created by 王兴海 on 2021/5/28.
//  Copyright © 2021 王兴海. All rights reserved.
//

#import "VL0View.h"
@interface VL0View()
@property(nonatomic,strong)UIImageView *iconImageview;
@property(nonatomic,strong)UILabel *titleLabel;
@property(nonatomic,strong)UILabel *batteryTitle;
@property(nonatomic,strong)UIImageView *batteryImageView;
@property(nonatomic,strong)UIImageView *arrorImage;
@end


@implementation VL0View

- (id)initWithIcon:(NSString*)icon title:(NSString*)title batteryTitle:(NSString*)batteryTitle battery:(int)battery
{
    if (self = [super init]) {
        self.iconImageview.image = [UIImage imageNamed:icon];
        self.titleLabel.text = title;
        self.arrorImage.image = [UIImage imageNamed:@"vl0_next"];
    }
    return self;
}




- (UIImageView*)iconImageview
{
    if (!_iconImageview) {
         _iconImageview = [[UIImageView alloc]init];
         _iconImageview.contentMode = UIViewContentModeCenter;
        [self addSubview:_iconImageview];
        [_iconImageview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_left).offset(13);
            make.centerY.equalTo(self.mas_centerY);
            make.height.width.mas_offset(20);
        }];
    }
    return _iconImageview;
}


- (UILabel*)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.numberOfLines = 0;
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:18.0];
        _titleLabel.textColor = [HexChangeRGB colorWithHexString:@"#333333"];
        [self addSubview:_titleLabel];
        [_titleLabel sizeToFit];
        [_titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.iconImageview.mas_centerY);
            make.left.equalTo(self.iconImageview.mas_right).offset(10);
        }];
    }
    return _titleLabel;
}


- (UILabel*)batteryTitle
{
    if (!_batteryTitle) {
        _batteryTitle = [[UILabel alloc]init];
        _batteryTitle.numberOfLines = 0;
        _batteryTitle.textAlignment = NSTextAlignmentLeft;
        _batteryTitle.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12.0];
        _batteryTitle.textColor = [HexChangeRGB colorWithHexString:@"#999999"];
        [self addSubview:_batteryTitle];
        [_batteryTitle sizeToFit];
        [_batteryTitle mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.mas_bottom).offset(-2);
            make.left.equalTo(self.titleLabel.mas_left);
        }];
    }
    return _batteryTitle;
}

- (UIImageView*)batteryImageView
{
    if (!_batteryImageView) {
         _batteryImageView = [[UIImageView alloc]init];
        [self addSubview:_batteryImageView];
        [_batteryImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.arrorImage.mas_left).offset(-20);
            make.centerY.equalTo(self.mas_centerY);
            make.height.mas_offset(10);
            make.width.mas_offset(10);
        }];
    }
    return _batteryImageView;
}


- (UIImageView*)arrorImage
{
    if (!_arrorImage) {
        _arrorImage = [[UIImageView alloc]init];
        [self addSubview:_arrorImage];
        [_arrorImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.mas_right).offset(-14);
            make.centerY.equalTo(self.mas_centerY);
            make.height.mas_offset(17);
            make.width.mas_offset(7);
        }];
    }
    return _arrorImage;
}






- (void)setNewMessage:(BOOL)newMessage
{
    _newMessage = newMessage;
    if (_newMessage) {
        self.batteryImageView.image = [UIImage imageNamed:@"vl0_new_msg"];
    }else{
        if (_batteryImageView) {
            [_batteryImageView removeFromSuperview];
             _batteryImageView = nil;
        }
    }
}


@end
